const app = getApp()
var loginUrl = "lkApi/getUserInfoByThirdAcc";
var nickName;
var photo;

Page({
  data: {
    balance: 0,
    freeze: 0
  },
  onLoad() {

  },
  onShow() {
    this.getUserInfo();
    this.setData({
      version: app.globalData.version
    });

  },
  // getUserInfo: function (cb) {
  //   var that = this;
  //   wx.login({
  //     success: function (res) {
  //       console.log(res);
  //       var code = res.code;
  //        wx.request({
  //         url: "https://api.weixin.qq.com/sns/jscode2session",
  //         header: {
  //           'content-type': 'application/json'
  //         },
  //         method: 'POST',
  //         data: {//这里写你要请求的参数
  //           appid: 'wx03db6ce69efca914',
  //           secret: '2f641ff6849681097c124c8a55066d73',
  //           js_code: code,
  //           grant_type: 'authorization_code'
  //         },
  //         success: function (res) {
  //           //将获取到的json数据，unionid
  //           console.log(res.data)//打印日志,
  //          var unionid = res.data.unionid;

  //           wx.getUserInfo({
  //         success: function (res) {

  //           console.log(res);
  //           nickName = res.userInfo.nickName;
  //           photo = res.userInfo.avatarUrl;
  //           this.toLogin(unionid);

  //         }
  //       })
  //         }
  //       })
  //     }
  //   })
  // },
  // toLogin: function (unionid) {

  //   //第三方登录接口调用
  //   wx.request({

  //     url: app.globalData.requestUrl + loginUrl,
  //     header: {
  //       'content-type': 'application/json'
  //     },
  //     method: 'POST',
  //     data: {//这里写你要请求的参数
  //       thirdAccType  : '01',
  //       nikename : nickName,
  //       photo: photo,
  //       thirdAccFlagOne: unionid
  //     },

  //     success: function (res) {
  //       //将获取到的json数据，
  //       console.log(res.data)//打印日志,
  //       // that.setData({
  //           //   userInfo: res.userInfo
  //           // });
  //     }
  //   })
  // },
  toMyOrder: function () {
    wx.navigateTo({
      url: "/pages/myorder/myorder"
    });
  },
  goDfk:function() {
    wx.navigateTo({
      url: "/pages/order-dfk/order-dfk"
    });
  },
  goDfh: function () {
    wx.navigateTo({
      url: "/pages/order-dfh/order-dfh"
    });
  },
  goDsh: function () {
    wx.navigateTo({
      url: "/pages/order-dsh/order-dsh"
    });
  },
  goDpj: function () {
    wx.showModal({
      title: '提示',
      content: '敬请期待',
      showCancel: false
    })
  },
  goService: function () {
    wx.showModal({
      title: '提示',
      content: '敬请期待',
      showCancel: false
    })
  },
  getUserInfo: function (cb) {
    var that = this
    wx.login({
      success: function () {
        wx.getUserInfo({
          success: function (res) {
            that.setData({
              userInfo: res.userInfo
            });
          }
        })
      }
    })
  },
  aboutUs: function () {
    wx.showModal({
      title: '关于我们',
      content: '本系统为老农瓜果小程序，祝大家使用愉快！',
      showCancel: false
    })
  },
  getPhoneNumber: function (e) {
    if (!e.detail.errMsg || e.detail.errMsg != "getPhoneNumber:ok") {
      wx.showModal({
        title: '提示',
        content: '无法获取手机号码',
        showCancel: false
      })
      return;
    }
    var that = this;
    wx.request({
      url: '',
      data: {
        token: app.globalData.token,
        encryptedData: e.detail.encryptedData,
        iv: e.detail.iv
      },
      success: function (res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '绑定成功',
            icon: 'success',
            duration: 2000
          })
          that.getUserApiInfo();
        } else {
          wx.showModal({

            title: '提示',
            content: '绑定失败',
            showCancel: false
          })
        }
      }
    })
  },


  relogin: function () {
    var that = this;
    app.globalData.token = null;
    app.login();
    wx.showModal({
      title: '提示',
      content: '重新登陆成功',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          that.onShow();
        }
      }
    })
  },
  mybalance: function () {
    wx.navigateTo({
      url: '/pages/mybalance/mybalance',
    })
  },

})